package com.wys.ws_im.controller;

import com.wys.ws_im.service.ChatService;
import com.wys.ws_im.utils.ResultUtil;
import com.wys.ws_im.vo.ResultVO;
import com.wys.ws_im.vo.ServiceListVO;
import com.wys.ws_im.vo.UserListVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 聊天信息获取
 *
 * @author wys
 * created in 23:40 2019/4/20
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/chat")
public class ChatController {

    @Autowired
    private ChatService chatService;

    @Autowired
    private LoginState loginState;

    /**
     * 用户获取聊天列表
     * @param aid
     * @return
     */
    @GetMapping("/users/get")
    public ResultVO getServiceCMList(@RequestParam Integer aid,
                                   HttpSession session) {

//        loginState.loginState(uid, session);
        List<ServiceListVO> serviceList = chatService.getServiceCMList(aid);

        return ResultUtil.success(0, "获取成功", serviceList);
    }

    /**
     * 客服获取聊天列表
     * @param aid
     * @param session
     * @return
     */
    @GetMapping("/services/get")
    public ResultVO getUserCMList(@RequestParam Integer aid,
                                   HttpSession session) {

//        loginState.loginState(serviceId, session);
        List<UserListVO> serviceList = chatService.getUserCMList(aid);

        return ResultUtil.success(0, "获取成功", serviceList);
    }


    /**
     * 选择客服，增加聊天客服
     * 如果是新的客服，就增加到客服聊天列表中
     * 如果不是，就获取最近三十天内的联系人
     *
     * @param aid
     * @param serviceId
     * @return
     */
    @GetMapping("/addService")
    public ResultVO addService(Integer aid, Integer serviceId) {

//        loginState.loginState(uid, session);
        List<ServiceListVO> serviceListVOS = chatService.addService(aid, serviceId);
        return ResultUtil.success(0, "获取成功", serviceListVOS);
    }


}
